## Makefile
##
## Copyright 2006, Brian Swetland.  All rights reserved.
## See provided LICENSE file or http://frotz.net/LICENSE for details.
##

#WITH_JTAG := true
#WITH_DEBUG_SUPPORT := true

CC      := arm-elf-gcc
OBJCOPY := arm-elf-objcopy
OBJDUMP := arm-elf-objdump

vpath %.c ../library
vpath %.S ../library

CFLAGS  := -O2 -g -Wall -I. -I../library
CFLAGS  += -DUSB_VENDOR=0x4242 -DUSB_PRODUCT=0x0001

CFLAGS  += -mthumb -mthumb-interwork
ASFLAGS += -mthumb-interwork

TARGET  := bootloader
OBJS    := crt0_rom.o init_clock.o
OBJS    += bootloader.o usb.o usb_debug.o

ifeq ($(WITH_JTAG),true)
vpath %.c ../jtag
CFLAGS	+= -DWITH_JTAG=1 -I../jtag
ASFLAGS += -DWITH_JTAG=1
OBJS    += jtag.o arm7tdmi.o
endif

ifeq ($(WITH_DEBUG_SUPPORT),true)
ASFLAGS += -DWITH_DEBUG_SUPPORT=1
endif

LIBGCC := `arm-elf-gcc $(CFLAGS) --print-libgcc-file-name`

all: $(TARGET) $(TARGET).lst

$(TARGET).elf: $(OBJS)
	arm-elf-ld --script ../library/rom.ld -o $(TARGET).elf $(OBJS) $(LIBGCC)

$(TARGET): $(TARGET).elf
	$(OBJCOPY) -O binary $(TARGET).elf $(TARGET)

$(TARGET).lst: $(TARGET).elf
	$(OBJDUMP) -d $(TARGET).elf > $(TARGET).lst

clean:
	rm -f *.o *~ *.elf *.lst $(TARGET) 

